package cn.net.yugu.doraemon.netty.protocol.msg05;

import cn.net.yugu.doraemon.netty.msg.TypeOperator;
import cn.net.yugu.doraemon.netty.protocol.MsgCode;
import io.netty.buffer.ByteBuf;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 电池心跳
 */
public class Msg051000001 extends Msg051 {
    public String code;
    public byte commType;
    public String server;
    public long createTime = System.currentTimeMillis();
    public Data data = new Data();

    public String bizServerId; //非协议字段

    public static class Data extends TypeOperator {
        public int msgCode;
        public int time;
        public int serial;
        public int signType;
        public String sign;
        public int heartType;
        public String jsonData;
        public transient Body body = new Body();

        public void read(ByteBuf buf) {
            msgCode = buf.readInt();
            time = buf.readInt();
            serial = buf.readInt();
            signType = buf.readByte();
            sign = readString(buf);
            heartType = buf.readInt();
            jsonData = readString(buf);
            body.read(buf);
        }

        public void write(ByteBuf buf) {
            buf.writeInt(msgCode);
            buf.writeInt(time);
            buf.writeInt(serial);
            buf.writeByte(signType);
            writeString(buf, sign);
            buf.writeInt(heartType);
            writeString(buf, jsonData);
            body.write(buf);
        }
    }

    public static class Pair extends TypeOperator {
        public String k;
        public String v;

        public Pair() {
        }

        public Pair(String k, String v) {
            this.k = k;
            this.v = v;
        }

        public void read(ByteBuf buf) {
            k = readString(buf);
            v = readString(buf);
        }

        public void write(ByteBuf buf) {
            writeString(buf, k);
            writeString(buf, v);
        }
    }

    public static class Body extends TypeOperator {
        public String IMEI;//电池IMEI
        public String CCID;//Sim卡CCID号
        public String BmsVer;//BMS版本
        public Integer LocType;//位置类型（1.GPS 2.CELL）
        public Integer Sig;//信号强度（1-31）
        public Integer SigType;//信号类型
        public String LBS;//基站信息“mcc,mnc,lac,cellid”
        public String Lng;//经度
        public String Lat;//纬度
        public Integer Vol;//总电压,mV
        public Integer Cur;//电流,单位mA,放电负，充电正
        public Integer Cells;//电芯串数
        public String VolList;//单体电压列表，单位mV
        public Integer Bal;//电芯的均衡状态0关闭,1开启
        public Integer BalCur;//主动均衡电流值，单位mA
        public String Temp;//温度
        public Integer ResCap;//剩余容量,单位mAH
        public Integer Soc;//Soc电量，单位0.1%
        public Integer Circle;//循环次数
        public Integer MOS;//充放电MOS状态
        public Integer Fault;//故障类型
        public Integer Heart;//心跳间隔
        public Integer Motion;//运动值(0:静止,1-10:运动等级)
        public Integer Uncap;//开盖状态(0:未开盖 1:开盖)
        public Integer Mode;//工作状态：0正常，1：待机
        public String Protect;//保护次数列表
        public Integer BatteryLease;//电池租期
        public Integer Status;
        /**
         * 安全断电状态, 1:开启, 0:关闭.
         */
        public Integer SafeShut;
        //long heart
        public String CellModel;//电池型号
        public String CellMFR;//电芯厂家
        public String BattMFR;//电池厂家
        public String MFD;//生产日期
        public String BmsModel;//BMS型号
        public Integer Mat;//材质（1.三元,2.磷酸铁锂,3.铅酸）
        public Integer BattType;//电池类型
        public Integer NomCap;//标准容量,单位mAH
        public Integer CircleCap;//循环容量,单位mAH
        public Integer CellFullVol;//单体充满电压，单位mV
        public Integer CellCutVol;//单体截止电压，单位mV
        public Integer SelfDsgRate;//自放电率，单位0.1%
        public String OCVTable;//开路电压值,单位mV

        public Integer COVTrip;//单体过压保护阈值，单位mV
        public Integer COVResm;//单体过压恢复阈值，单位mV
        public Integer COVDelay;//单体过压延时，单位S
        public Integer CUVTrip;//单体欠压保护阈值，单位mV
        public Integer CUVResm;//单体欠压恢复阈值，单位mV
        public Integer CUVDelay;//单体欠压延时，单位S
        public Integer POVTrip;//整体过压保护阈值，单位mV
        public Integer POVResm;//整体过压恢复阈值，单位mV
        public Integer POVDelay;//整体过压延时，单位S
        public Integer PUVTrip;//整体欠压保护阈值，单位mV
        public Integer PUVResm;//整体欠压恢复阈值，单位mV
        public Integer PUVDelay;//整体欠压延时，单位S
        public Integer ChgOTTrip;//充电高温保护阈值，单位0.1K
        public Integer ChgOTResm;//充电高温恢复阈值，单位0.1K
        public Integer ChgOTDelay;//充电高温延时，单位S
        public Integer ChgUTTrip;//充电低温保护阈值，单位0.1K
        public Integer ChgUTResm;//充电低温恢复阈值，单位0.1K
        public Integer ChgUTDelay;//充电低温延时，单位S
        public Integer DsgOTTrip;//放电高温保护阈值，单位0.1K
        public Integer DsgOTResm;//放电高温恢复阈值，单位0.1K
        public Integer DsgOTDelay;//放电高温延时，单位S
        public Integer DsgUTTrip;//放电低温保护阈值，单位0.1K
        public Integer DsgUTResm;//放电低温恢复阈值，单位0.1K
        public Integer DsgUTDelay;//放电低温延时，单位S
        public Integer ChgOCTrip;//充电过流保护阈值，单位mA
        public Integer ChgOCDelay;//充电过流延时，单位S
        public Integer ChgOCRels;//充电过流释放时间，单位S
        public Integer DsgOCTrip;//放电过流保护阈值，单位mA
        public Integer DsgOCDelay;//放电过流延时，单位S
        public Integer DsgOCRels;//放电过流释放时间，单位S
        public Integer RSNS;//1：硬件过流、短路保护阈值翻倍
        public Integer HardOCTrip;//硬件过流保护阈值
        public Integer HardOCDelay;//硬件过流保护延时
        public Integer SCTrip;//短路保护阈值
        public Integer SCDelay;//短路保护延时
        public Integer HardOVTrip;//硬件单体过压保护阈值,单位mV
        public Integer HardOVDelay;//硬件单体过压保护延时
        public Integer HardUVTrip;//硬件单体欠压保护阈值,单位mV
        public Integer HardUVDelay;//硬件单体欠压保护延时
        public Integer SDRels;//短路释放时间
        public Integer Function;//功能配置
        public Integer NTCConfig;//NTC配置
        public Integer SampleR;//电流采样电阻值，单位0.1R
        public Integer Motionless; //静止状态时心跳间隔
        public Integer Standby;        //存储状态时心跳间隔
        public Integer Dormancy;        //休眠状态时心跳间隔
        public Long MaxCap;//实际容量,单位mAH
        public Integer BalStart;//均衡开启电压
        public Integer BalDiff;//均衡精度
        public Integer BalEnd;//均衡停止电压
        public Integer ParaMode;
        /**
         * 安全断电时间, 09:00-10:10
         */
        public String ShutTime;

        public void read(ByteBuf buf) {
            int size = buf.readInt();
            for (int i = 0; i < size; i++) {
                Pair pair = new Pair();
                pair.read(buf);
                if ("IMEI".equals(pair.k)) {
                    IMEI = pair.v;
                } else if ("CCID".equals(pair.k)) {
                    CCID = pair.v;
                } else if ("BmsVer".equals(pair.k)) {
                    BmsVer = pair.v;
                } else if ("LocType".equals(pair.k)) {
                    LocType = Integer.parseInt(pair.v);
                } else if ("Sig".equals(pair.k)) {
                    Sig = Integer.parseInt(pair.v);
                } else if ("SigType".equals(pair.k)) {
                    SigType = Integer.parseInt(pair.v);
                } else if ("LBS".equals(pair.k)) {
                    LBS = pair.v;
                } else if ("Lng".equals(pair.k)) {
                    Lng = pair.v;
                } else if ("Lat".equals(pair.k)) {
                    Lat = pair.v;
                } else if ("Vol".equals(pair.k)) {
                    Vol = Integer.parseInt(pair.v);
                } else if ("Cur".equals(pair.k)) {
                    Cur = Integer.parseInt(pair.v);
                } else if ("Cells".equals(pair.k)) {
                    Cells = Integer.parseInt(pair.v);
                } else if ("VolList".equals(pair.k)) {
                    VolList = pair.v;
                } else if ("Bal".equals(pair.k)) {
                    Bal = Integer.parseInt(pair.v);
                } else if ("BalCur".equals(pair.k)) {
                    BalCur = Integer.parseInt(pair.v);
                } else if ("Temp".equals(pair.k)) {
                    Temp = pair.v;
                } else if ("ResCap".equals(pair.k)) {
                    ResCap = Integer.parseInt(pair.v);
                } else if ("Soc".equals(pair.k)) {
                    Soc = Integer.parseInt(pair.v);
                } else if ("Circle".equals(pair.k)) {
                    Circle = Integer.parseInt(pair.v);
                } else if ("MOS".equals(pair.k)) {
                    MOS = Integer.parseInt(pair.v);
                } else if ("Fault".equals(pair.k)) {
                    Fault = Integer.parseInt(pair.v);
                } else if ("Heart".equals(pair.k)) {
                    Heart = Integer.parseInt(pair.v);
                } else if ("Motion".equals(pair.k)) {
                    Motion = Integer.parseInt(pair.v);
                } else if ("Uncap".equals(pair.k)) {
                    Uncap = Integer.parseInt(pair.v);
                } else if ("Mode".equals(pair.k)) {
                    Mode = Integer.parseInt(pair.v);
                } else if ("Protect".equals(pair.k)) {
                    Protect = pair.v;
                } else if ("BatteryLease".equals(pair.k)) {
                    BatteryLease = Integer.parseInt(pair.v);
                }  else if ("Status".equals(pair.k)) {
                    Status = Integer.parseInt(pair.v);
                } else if ("CellModel".equals(pair.k)) {
                    CellModel = pair.v;
                } else if ("CellMFR".equals(pair.k)) {
                    CellMFR = pair.v;
                } else if ("BattMFR".equals(pair.k)) {
                    BattMFR = pair.v;
                } else if ("MFD".equals(pair.k)) {
                    MFD = pair.v;
                } else if ("BmsModel".equals(pair.k)) {
                    BmsModel = pair.v;
                } else if ("Mat".equals(pair.k)) {
                    Mat = Integer.parseInt(pair.v);
                } else if ("BattType".equals(pair.k)) {
                    BattType = Integer.parseInt(pair.v);
                } else if ("NomCap".equals(pair.k)) {
                    NomCap = Integer.parseInt(pair.v);
                } else if ("CircleCap".equals(pair.k)) {
                    CircleCap = Integer.parseInt(pair.v);
                } else if ("CellFullVol".equals(pair.k)) {
                    CellFullVol = Integer.parseInt(pair.v);
                } else if ("CellCutVol".equals(pair.k)) {
                    CellCutVol = Integer.parseInt(pair.v);
                } else if ("SelfDsgRate".equals(pair.k)) {
                    SelfDsgRate = Integer.parseInt(pair.v);
                } else if ("OCVTable".equals(pair.k)) {
                    OCVTable = pair.v;
                } else if ("COVTrip".equals(pair.k)) {
                    COVTrip = Integer.parseInt(pair.v);
                } else if ("COVResm".equals(pair.k)) {
                    COVResm = Integer.parseInt(pair.v);
                } else if ("COVDelay".equals(pair.k)) {
                    COVDelay = Integer.parseInt(pair.v);
                } else if ("CUVTrip".equals(pair.k)) {
                    CUVTrip = Integer.parseInt(pair.v);
                } else if ("CUVResm".equals(pair.k)) {
                    CUVResm = Integer.parseInt(pair.v);
                } else if ("CUVDelay".equals(pair.k)) {
                    CUVDelay = Integer.parseInt(pair.v);
                } else if ("POVTrip".equals(pair.k)) {
                    POVTrip = Integer.parseInt(pair.v);
                } else if ("POVResm".equals(pair.k)) {
                    POVResm = Integer.parseInt(pair.v);
                } else if ("POVDelay".equals(pair.k)) {
                    POVDelay = Integer.parseInt(pair.v);
                } else if ("PUVTrip".equals(pair.k)) {
                    PUVTrip = Integer.parseInt(pair.v);
                } else if ("PUVResm".equals(pair.k)) {
                    PUVResm = Integer.parseInt(pair.v);
                } else if ("PUVDelay".equals(pair.k)) {
                    PUVDelay = Integer.parseInt(pair.v);
                } else if ("ChgOTTrip".equals(pair.k)) {
                    ChgOTTrip = Integer.parseInt(pair.v);
                } else if ("ChgOTResm".equals(pair.k)) {
                    ChgOTResm = Integer.parseInt(pair.v);
                } else if ("ChgOTDelay".equals(pair.k)) {
                    ChgOTDelay = Integer.parseInt(pair.v);
                } else if ("ChgUTTrip".equals(pair.k)) {
                    ChgUTTrip = Integer.parseInt(pair.v);
                } else if ("ChgUTResm".equals(pair.k)) {
                    ChgUTResm = Integer.parseInt(pair.v);
                } else if ("ChgUTDelay".equals(pair.k)) {
                    ChgUTDelay = Integer.parseInt(pair.v);
                } else if ("DsgOTTrip".equals(pair.k)) {
                    DsgOTTrip = Integer.parseInt(pair.v);
                } else if ("DsgOTResm".equals(pair.k)) {
                    DsgOTResm = Integer.parseInt(pair.v);
                } else if ("DsgOTDelay".equals(pair.k)) {
                    DsgOTDelay = Integer.parseInt(pair.v);
                } else if ("DsgUTTrip".equals(pair.k)) {
                    DsgUTTrip = Integer.parseInt(pair.v);
                } else if ("DsgUTResm".equals(pair.k)) {
                    DsgUTResm = Integer.parseInt(pair.v);
                } else if ("DsgUTDelay".equals(pair.k)) {
                    DsgUTDelay = Integer.parseInt(pair.v);
                } else if ("ChgOCTrip".equals(pair.k)) {
                    ChgOCTrip = Integer.parseInt(pair.v);
                } else if ("ChgOCDelay".equals(pair.k)) {
                    ChgOCDelay = Integer.parseInt(pair.v);
                } else if ("ChgOCRels".equals(pair.k)) {
                    ChgOCRels = Integer.parseInt(pair.v);
                } else if ("DsgOCTrip".equals(pair.k)) {
                    DsgOCTrip = Integer.parseInt(pair.v);
                } else if ("DsgOCDelay".equals(pair.k)) {
                    DsgOCDelay = Integer.parseInt(pair.v);
                } else if ("DsgOCRels".equals(pair.k)) {
                    DsgOCRels = Integer.parseInt(pair.v);
                } else if ("RSNS".equals(pair.k)) {
                    RSNS = Integer.parseInt(pair.v);
                } else if ("HardOCTrip".equals(pair.k)) {
                    HardOCTrip = Integer.parseInt(pair.v);
                } else if ("HardOCDelay".equals(pair.k)) {
                    HardOCDelay = Integer.parseInt(pair.v);
                } else if ("SCTrip".equals(pair.k)) {
                    SCTrip = Integer.parseInt(pair.v);
                } else if ("SCDelay".equals(pair.k)) {
                    SCDelay = Integer.parseInt(pair.v);
                } else if ("HardOVTrip".equals(pair.k)) {
                    HardOVTrip = Integer.parseInt(pair.v);
                } else if ("HardOVDelay".equals(pair.k)) {
                    HardOVDelay = Integer.parseInt(pair.v);
                } else if ("HardUVTrip".equals(pair.k)) {
                    HardUVTrip = Integer.parseInt(pair.v);
                } else if ("HardUVDelay".equals(pair.k)) {
                    HardUVDelay = Integer.parseInt(pair.v);
                } else if ("SDRels".equals(pair.k)) {
                    SDRels = Integer.parseInt(pair.v);
                } else if ("Function".equals(pair.k)) {
                    Function = Integer.parseInt(pair.v);
                } else if ("NTCConfig".equals(pair.k)) {
                    NTCConfig = Integer.parseInt(pair.v);
                } else if ("SampleR".equals(pair.k)) {
                    SampleR = Integer.parseInt(pair.v);
                } else if ("Motionless".equals(pair.k)) {
                    Motionless = Integer.parseInt(pair.v);
                } else if ("Standby".equals(pair.k)) {
                    Standby = Integer.parseInt(pair.v);
                } else if ("Dormancy".equals(pair.k)) {
                    Dormancy = Integer.parseInt(pair.v);
                } else if ("MaxCap".equals(pair.k)) {
                    MaxCap = Long.parseLong(pair.v);
                } else if ("BalStart".equals(pair.k)) {
                    BalStart = Integer.parseInt(pair.v);
                } else if ("BalDiff".equals(pair.k)) {
                    BalDiff = Integer.parseInt(pair.v);
                } else if ("BalEnd".equals(pair.k)) {
                    BalEnd = Integer.parseInt(pair.v);
                } else if ("ParaMode".equals(pair.k)) {
                    ParaMode = Integer.parseInt(pair.v);
                } else if ("SafeShut".equals(pair.k)) {
                    SafeShut = Integer.parseInt(pair.v);
                } else if ("ShutTime".equals(pair.k)) {
                    ShutTime = pair.v;
                }
            }
        }

        public void write(ByteBuf buf) {
            List<Pair> pairList = new ArrayList<Pair>();
            if (StringUtils.isNotEmpty(IMEI)) { pairList.add(new Pair("IMEI", IMEI)); }
            if (StringUtils.isNotEmpty(CCID)) { pairList.add(new Pair("CCID", CCID)); }
            if (StringUtils.isNotEmpty(BmsVer)) {pairList.add(new Pair("BmsVer", BmsVer));}
            if (null != LocType) {pairList.add(new Pair("LocType", String.valueOf(LocType)));}
            if (null != Sig) {pairList.add(new Pair("Sig", String.valueOf(Sig)));}
            if (null != SigType) {pairList.add(new Pair("SigType", String.valueOf(SigType)));}
            if (StringUtils.isNotEmpty(LBS)) {pairList.add(new Pair("LBS", LBS));}
            if (StringUtils.isNotEmpty(Lng)) {pairList.add(new Pair("Lng", Lng));}
            if (StringUtils.isNotEmpty(Lat)) {pairList.add(new Pair("Lat", Lat));}
            if (null != Vol) {pairList.add(new Pair("Vol", String.valueOf(Vol)));}
            if (null != Cur) {pairList.add(new Pair("Cur", String.valueOf(Cur)));}
            if (null != Cells) {pairList.add(new Pair("Cells", String.valueOf(Cells)));}
            if (null != VolList) {pairList.add(new Pair("VolList", VolList));}
            if (null != Bal) {pairList.add(new Pair("Bal", String.valueOf(Bal)));}
            if (null != BalCur) {pairList.add(new Pair("BalCur", String.valueOf(BalCur)));}
            if (StringUtils.isNotEmpty(Temp)) {pairList.add(new Pair("Temp", Temp));}
            if (null != ResCap) {pairList.add(new Pair("ResCap", String.valueOf(ResCap)));}
            if (null != Soc) {pairList.add(new Pair("Soc", String.valueOf(Soc)));}
            if (null != Circle) {pairList.add(new Pair("Circle", String.valueOf(Circle)));}
            if (null != MOS) {pairList.add(new Pair("MOS", String.valueOf(MOS)));}
            if (null != Fault) {pairList.add(new Pair("Fault", String.valueOf(Fault)));}
            if (null != Heart) {pairList.add(new Pair("Heart", String.valueOf(Heart)));}
            if (null != Motion) {pairList.add(new Pair("Motion", String.valueOf(Motion)));}
            if (null != Uncap) {pairList.add(new Pair("Uncap", String.valueOf(Uncap)));}
            if (null != Mode) {pairList.add(new Pair("Mode", String.valueOf(Mode)));}
            if (StringUtils.isNotEmpty(Protect)) {pairList.add(new Pair("Protect", Protect));}
            if (null != BatteryLease) {pairList.add(new Pair("BatteryLease", String.valueOf(BatteryLease)));}
            if (null != Status) {pairList.add(new Pair("Status", String.valueOf(Status)));}
            if (StringUtils.isNotEmpty(CellModel)) {pairList.add(new Pair("CellModel", CellModel));}
            if (StringUtils.isNotEmpty(CellMFR)) {pairList.add(new Pair("CellMFR", CellMFR));}
            if (StringUtils.isNotEmpty(BattMFR)) {pairList.add(new Pair("BattMFR", BattMFR));}
            if (StringUtils.isNotEmpty(MFD)) {pairList.add(new Pair("MFD", MFD));}
            if (StringUtils.isNotEmpty(BmsModel)) {pairList.add(new Pair("BmsModel", BmsModel));}
            if (null != Mat) {pairList.add(new Pair("Mat", String.valueOf(Mat)));}
            if (null != BattType) {pairList.add(new Pair("BattType", String.valueOf(BattType)));}
            if (null != NomCap) {pairList.add(new Pair("NomCap", String.valueOf(NomCap)));}
            if (null != CircleCap) {pairList.add(new Pair("CircleCap", String.valueOf(CircleCap)));}
            if (null != CellFullVol) {pairList.add(new Pair("CellFullVol", String.valueOf(CellFullVol)));}
            if (null != CellCutVol) {pairList.add(new Pair("CellCutVol", String.valueOf(CellCutVol)));}
            if (null != SelfDsgRate) {pairList.add(new Pair("SelfDsgRate", String.valueOf(SelfDsgRate)));}
            if (StringUtils.isNotEmpty(OCVTable)) {pairList.add(new Pair("OCVTable", OCVTable));}
            if (null != COVTrip) {pairList.add(new Pair("COVTrip", String.valueOf(COVTrip)));}
            if (null != COVResm) {pairList.add(new Pair("COVResm", String.valueOf(COVResm)));}
            if (null != COVDelay) {pairList.add(new Pair("COVDelay", String.valueOf(COVDelay)));}
            if (null != CUVTrip) {pairList.add(new Pair("CUVTrip", String.valueOf(CUVTrip)));}
            if (null != CUVResm) {pairList.add(new Pair("CUVResm", String.valueOf(CUVResm)));}
            if (null != CUVDelay) {pairList.add(new Pair("CUVDelay", String.valueOf(CUVDelay)));}
            if (null != POVTrip) {pairList.add(new Pair("POVTrip", String.valueOf(POVTrip)));}
            if (null != POVResm) {pairList.add(new Pair("POVResm", String.valueOf(POVResm)));}
            if (null != POVDelay) {pairList.add(new Pair("POVDelay", String.valueOf(POVDelay)));}
            if (null != PUVTrip) {pairList.add(new Pair("PUVTrip", String.valueOf(PUVTrip)));}
            if (null != PUVResm) {pairList.add(new Pair("PUVResm", String.valueOf(PUVResm)));}
            if (null != PUVDelay) {pairList.add(new Pair("PUVDelay", String.valueOf(PUVDelay)));}
            if (null != ChgOTTrip) {pairList.add(new Pair("ChgOTTrip", String.valueOf(ChgOTTrip)));}
            if (null != ChgOTResm) {pairList.add(new Pair("ChgOTResm", String.valueOf(ChgOTResm)));}
            if (null != ChgOTDelay) {pairList.add(new Pair("ChgOTDelay", String.valueOf(ChgOTDelay)));}
            if (null != ChgUTTrip) {pairList.add(new Pair("ChgUTTrip", String.valueOf(ChgUTTrip)));}
            if (null != ChgUTResm) {pairList.add(new Pair("ChgUTResm", String.valueOf(ChgUTResm)));}
            if (null != ChgUTDelay) {pairList.add(new Pair("ChgUTDelay", String.valueOf(ChgUTDelay)));}
            if (null != DsgOTTrip) {pairList.add(new Pair("DsgOTTrip", String.valueOf(DsgOTTrip)));}
            if (null != DsgOTResm) {pairList.add(new Pair("DsgOTResm", String.valueOf(DsgOTResm)));}
            if (null != DsgOTDelay) {pairList.add(new Pair("DsgOTDelay", String.valueOf(DsgOTDelay)));}
            if (null != DsgUTTrip) {pairList.add(new Pair("DsgUTTrip", String.valueOf(DsgUTTrip)));}
            if (null != DsgUTResm) {pairList.add(new Pair("DsgUTResm", String.valueOf(DsgUTResm)));}
            if (null != DsgUTDelay) {pairList.add(new Pair("DsgUTDelay", String.valueOf(DsgUTDelay)));}
            if (null != ChgOCTrip) {pairList.add(new Pair("ChgOCTrip", String.valueOf(ChgOCTrip)));}
            if (null != ChgOCDelay) {pairList.add(new Pair("ChgOCDelay", String.valueOf(ChgOCDelay)));}
            if (null != ChgOCRels) {pairList.add(new Pair("ChgOCRels", String.valueOf(ChgOCRels)));}
            if (null != DsgOCTrip) {pairList.add(new Pair("DsgOCTrip", String.valueOf(DsgOCTrip)));}
            if (null != DsgOCDelay) {pairList.add(new Pair("DsgOCDelay", String.valueOf(DsgOCDelay)));}
            if (null != DsgOCRels) {pairList.add(new Pair("DsgOCRels", String.valueOf(DsgOCRels)));}
            if (null != RSNS) {pairList.add(new Pair("RSNS", String.valueOf(RSNS)));}
            if (null != HardOCTrip) {pairList.add(new Pair("HardOCTrip", String.valueOf(HardOCTrip)));}
            if (null != HardOCDelay) {pairList.add(new Pair("HardOCDelay", String.valueOf(HardOCDelay)));}
            if (null != SCTrip) {pairList.add(new Pair("SCTrip", String.valueOf(SCTrip)));}
            if (null != SCDelay) {pairList.add(new Pair("SCDelay", String.valueOf(SCDelay)));}
            if (null != HardOVTrip) {pairList.add(new Pair("HardOVTrip", String.valueOf(HardOVTrip)));}
            if (null != HardOVDelay) {pairList.add(new Pair("HardOVDelay", String.valueOf(HardOVDelay)));}
            if (null != HardUVTrip) {pairList.add(new Pair("HardUVTrip", String.valueOf(HardUVTrip)));}
            if (null != HardUVDelay) {pairList.add(new Pair("HardUVDelay", String.valueOf(HardUVDelay)));}
            if (null != SDRels) {pairList.add(new Pair("SDRels", String.valueOf(SDRels)));}
            if (null != Function) {pairList.add(new Pair("Function", String.valueOf(Function)));}
            if (null != NTCConfig) {pairList.add(new Pair("NTCConfig", String.valueOf(NTCConfig)));}
            if (null != SampleR) {pairList.add(new Pair("SampleR", String.valueOf(SampleR)));}
            if (null != Motionless) {pairList.add(new Pair("Motionless", String.valueOf(Motionless)));}
            if (null != Standby) {pairList.add(new Pair("Standby", String.valueOf(Standby)));}
            if (null != Dormancy) {pairList.add(new Pair("Dormancy", String.valueOf(Dormancy)));}
            if (null != MaxCap) {pairList.add(new Pair("MaxCap", String.valueOf(MaxCap)));}
            if (null != BalStart) {pairList.add(new Pair("BalStart", String.valueOf(BalStart)));}
            if (null != BalDiff) {pairList.add(new Pair("BalDiff", String.valueOf(BalDiff)));}
            if (null != BalEnd) {pairList.add(new Pair("BalEnd", String.valueOf(BalEnd)));}
            if (null != ParaMode) {pairList.add(new Pair("ParaMode", String.valueOf(ParaMode)));}
            if (null != SafeShut) { pairList.add(new Pair("SafeShut", String.valueOf(SafeShut))); }
            if (StringUtils.isNotBlank(ShutTime)) {
                pairList.add(new Pair("ShutTime", ShutTime));
            }
            buf.writeInt(pairList.size());
            for (Pair e : pairList) {
                e.write(buf);
            }
        }
    }

    public static Body setHeartParam(HeartParam param) {
        Body body = new Body();
        body.IMEI = param.IMEI;
        body.CCID = param.CCID;
        body.BmsVer = param.BmsVer;
        body.LocType = param.LocType;
        body.Sig = param.Sig;
        body.SigType = param.SigType;
        body.LBS = param.LBS;
        body.Lng = param.Lng;
        body.Lat = param.Lat;
        body.Vol = param.Vol;
        body.Cur = param.Cur;
        body.Cells = param.Cells;
        body.VolList = param.VolList;
        body.Bal = param.Bal;
        body.BalCur = param.BalCur;
        body.Temp = param.Temp;
        body.ResCap = param.ResCap;
        body.Soc = param.Soc;
        body.Circle = param.Circle;
        body.MOS = param.MOS;
        body.Fault = param.Fault;
        body.Heart = param.Heart;
        body.Motion = param.Motion;
        body.Uncap = param.Uncap;
        body.Mode = param.Mode;
        body.Protect = param.Protect;
        body.BatteryLease = param.BatteryLease;
        body.Status = param.Status;
        body.CellModel = param.CellModel;
        body.CellMFR = param.CellMFR;
        body.BattMFR = param.BattMFR;
        body.MFD = param.MFD;
        body.BmsModel = param.BmsModel;
        body.Mat = param.Mat;
        body.BattType = param.BattType;
        body.NomCap = param.NomCap;
        body.CircleCap = param.CircleCap;
        body.CellFullVol = param.CellFullVol;
        body.CellCutVol = param.CellCutVol;
        body.SelfDsgRate = param.SelfDsgRate;
        body.OCVTable = param.OCVTable;
        body.COVTrip = param.COVTrip;
        body.COVResm = param.COVResm;
        body.COVDelay = param.COVDelay;
        body.CUVTrip = param.CUVTrip;
        body.CUVResm = param.CUVResm;
        body.CUVDelay = param.CUVDelay;
        body.POVTrip = param.POVTrip;
        body.POVResm = param.POVResm;
        body.POVDelay = param.POVDelay;
        body.PUVTrip = param.PUVTrip;
        body.PUVResm = param.PUVResm;
        body.PUVDelay = param.PUVDelay;
        body.ChgOTTrip = param.ChgOTTrip;
        body.ChgOTResm = param.ChgOTResm;
        body.ChgOTDelay = param.ChgOTDelay;
        body.ChgUTTrip = param.ChgUTTrip;
        body.ChgUTResm = param.ChgUTResm;
        body.ChgUTDelay = param.ChgUTDelay;
        body.DsgOTTrip = param.DsgOTTrip;
        body.DsgOTResm = param.DsgOTResm;
        body.DsgOTDelay = param.DsgOTDelay;
        body.DsgUTTrip = param.DsgUTTrip;
        body.DsgUTResm = param.DsgUTResm;
        body.DsgUTDelay = param.DsgUTDelay;
        body.ChgOCTrip = param.ChgOCTrip;
        body.ChgOCDelay = param.ChgOCDelay;
        body.ChgOCRels = param.ChgOCRels;
        body.DsgOCTrip = param.DsgOCTrip;
        body.DsgOCDelay = param.DsgOCDelay;
        body.DsgOCRels = param.DsgOCRels;
        body.RSNS = param.RSNS;
        body.HardOCTrip = param.HardOCTrip;
        body.HardOCDelay = param.HardOCDelay;
        body.SCTrip = param.SCTrip;
        body.SCDelay = param.SCDelay;
        body.HardOVTrip = param.HardOVTrip;
        body.HardOVDelay = param.HardOVDelay;
        body.HardUVTrip = param.HardUVTrip;
        body.HardUVDelay = param.HardUVDelay;
        body.SDRels = param.SDRels;
        body.Function = param.Function;
        body.NTCConfig = param.NTCConfig;
        body.SampleR = param.SampleR;
        body.Motionless = param.Motionless;
        body.Standby = param.Standby;
        body.Dormancy = param.Dormancy;
        body.MaxCap = param.MaxCap;
        body.BalStart = param.BalStart;
        body.BalDiff = param.BalDiff;
        body.BalEnd = param.BalEnd;
        body.ParaMode = param.ParaMode;
        body.SafeShut = param.SafeShut;
        body.ShutTime = param.ShutTime;
        return body;
    }

    @Override
    public int getMsgCode() {
        return MsgCode.MSG_051000001.getCode();
    }

    @Override
    public void readData(ByteBuf buffer) {
        code = readString(buffer);
        commType = buffer.readByte();
        server = readString(buffer);
        createTime = buffer.readLong();
        data.read(buffer);
    }

    @Override
    public void writeData(ByteBuf buffer) {
        writeString(buffer, code);
        buffer.writeByte(commType);
        writeString(buffer, server);
        buffer.writeLong(createTime);
        data.write(buffer);
    }
}
